package com.css.sword.knowing.search.comm;

/**
 * 相关常量
 */

public class SearchConst {

    public static final String SYSTEMID_FIELD = "_systemid"; // 用于标识索引类型数据属于哪个系统
    public static final String PUBLIC_PRIV = "public"; // 如果该索引类型能够被所有系统访问，创建索引时systemid取此值
    public static final int BULK_SIZE = 2 * 1024 * 1024; // 创建索引时，所有数据大小不能超过此值，单位字节
    public static final String SYSTEMIDTEMPLATE = "12345678";

    // 范围比较常量
    public static final String COMPARISON_OP_GT = "gt"; // 大于
    public static final String COMPARISON_OP_LT = "lt"; // 小于
    public static final String COMPARISON_OP_GTE = "gte"; // 大于等于
    public static final String COMPARISON_OP_LTE = "lte"; // 小于等于

    public static final String SEARCH_NESTED = "nested"; // nested检索
    
    // 搜索方法常量
    public static final String SEARCH_METHOD_PHRASE = "phrase"; // 短语搜索，默认值
    public static final String SEARCH_METHOD_MATCH = "match"; // 分词搜索
    public static final String SEARCH_METHOD_WILDCARD = "wildcard"; // 通配符搜索
    public static final String SEARCH_METHOD_RANGE = "range"; // 范围搜索
    public static final String SEARCH_METHOD_TERM = "term"; // term过滤，精确匹配查询
    public static final String SEARCH_METHOD_TERMS = "terms"; // terms过滤，允许指定多个匹配条件
    public static final String SEARCH_METHOD_QUREY_STRING = "query_string"; // 字符串匹配
    public static final String SEARCH_METHOD_EXISTS = "exists"; // 字段值是否为空

    // 搜索项间关系常量
    public static final String SEARCH_OPERATOR_MUST = "must"; // 必须有
    public static final String SEARCH_OPERATOR_SHOULD = "should"; // 应当有
    public static final String SEARCH_OPERATOR_MUST_NOT = "must_not"; // 不应当有
    

    // preference选项，控制Bouncing Results（结果震荡）的选项
    public static final String SEARCH_PREFERENCE_PRIMARY = "_primary"; // 搜索只在主分片执行搜索请求，副本不参与搜索；性能会打折扣，达不到性能的水平扩展
    public static final String SEARCH_PREFERENCE_PRIMARY_FIRST = "_primary_first"; // 优先在主分片执行，如果主分片挂掉，会在副本执行请求
    public static final String SEARCH_PREFERENCE_REPLICA = "_replica"; // 搜索只在副本上执行搜索请求
    public static final String SEARCH_PREFERENCE_REPLICA_FIRST = "_replica_first"; // 优先在副本执行
    public static final String SEARCH_PREFERENCE_LOCAL = "_local"; // 搜索请求优先在本地执行
    public static final String SEARCH_PREFERENCE_PREFER_NODES = "_prefer_nodes:"; // 只在某节点执行搜索，例如：_prefer_nodes:abc,xyz
    public static final String SEARCH_PREFERENCE_SHRDDS = "_shards:"; // 搜索只在指定分片执行（_shards:2,3），可以与_primary参数一起使用如：_shards:2,3;_primary
    public static final String SEARCH_PREFERENCE_ONLY_NODES = "_only_nodes:"; // 搜索指定的节点
    public static final String SEARCH_PREFERENCE_CUSTOM = ""; // 指定一个随机字符串，可以保证同样的请求，被分配到同样的副本上面，从而保证同一请求结果的稳定性

    // 范围搜索值类型
    public static final String SEARCH_VALUE_TYPE_STRING = "string"; // 字符串
    public static final String SEARCH_VALUE_TYPE_INT = "int"; // 整型
    public static final String SEARCH_VALUE_TYPE_LONG = "long"; // 长整型
    public static final String SEARCH_VALUE_TYPE_FLOAT = "float"; // 浮点型
    public static final String SEARCH_VALUE_TYPE_DOUBLE = "double"; // 双精度型

    // 排序类型
    public static final int SEARCH_ORDER_TYPE_DESC = 0; // 降序排列
    public static final int SEARCH_ORDER_TYPE_ASC = 1; // 升序排列

    // 统计常量,指标类型
    public static final int AGG_METRICS_COUNT = 1;
    public static final int AGG_METRICS_SUM = 2;
    public static final int AGG_METRICS_AVG = 3;
    public static final int AGG_METRICS_MIN = 4;
    public static final int AGG_METRICS_MAX = 5;
    public static final int AGG_METRICS_ALL = 6;
    public static final int AGG_METRICS_ALL_EXTEND = 7;

    // 统计常量,统计类型
    public static final int AGG_TYPE_TERMS = 101;      //按字段值分组
    // public static final int AGG_TYPE_RANGE = 102;
    // public static final int AGG_TYPE_DATE_RANGE = 103;
    public static final int AGG_TYPE_HISTOGRAM = 104;      //普通直方图
    public static final int AGG_TYPE_DATE_HISTOGRAM = 105;  //按日期直方图

    // 指标键值
    public static final String AGG_METRICS_COUNT_KEY = "count";
    public static final String AGG_METRICS_SUM_KEY = "sum";
    public static final String AGG_METRICS_AVG_KEY = "avg";
    public static final String AGG_METRICS_MIN_KEY = "min";
    public static final String AGG_METRICS_MAX_KEY = "max";
    public static final String AGG_METRICS_STD_DEVIATION_KEY = "std_dev";
    public static final String AGG_METRICS_SUM_OF_SQUARES_KEY = "sum_squares";
    public static final String AGG_METRICS_VARIANCE_KEY = "variance";
    public static final String AGG_METRICS_DOCUMENT_COUNT_KEY = "document_count";

    // 日期直方图间隔
    public static final int AGG_INTERVAL_YEAR = 201;
    public static final int AGG_INTERVAL_QUARTER = 202;
    public static final int AGG_INTERVAL_MONTH = 203;
    public static final int AGG_INTERVAL_DAY = 204;
    public static final int AGG_INTERVAL_WEEK = 205;
    public static final int AGG_INTERVAL_HOUR = 206;
    public static final int AGG_INTERVAL_MINUTE = 207;
    public static final int AGG_INTERVAL_SECOND = 208;
    public static final int AGG_INTERVAL_CUSTOMER = 209;

    public static final int AGG_CUSTOMER_INTERVAL_DAY = 301;
    public static final int AGG_CUSTOMER_INTERVAL_WEEK = 302;
    public static final int AGG_CUSTOMER_INTERVAL_HOUR = 303;
    public static final int AGG_CUSTOMER_INTERVAL_MINUTE = 304;
    public static final int AGG_CUSTOMER_INTERVAL_SECOND = 305;

}
